package com.cdpm.system.service.impl;

import com.cdpm.common.core.domain.model.LoginUser;
import com.cdpm.common.utils.SecurityUtils;
import com.cdpm.common.utils.StringUtils;
import com.cdpm.system.domain.TStrategyConfig;
import com.cdpm.system.mapper.StrategyMapper;
import com.cdpm.system.service.IStrategyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: longjy
 * @create: 2024-08-26 09:38
 **/
@Service
public class StrategyServiceImpl implements IStrategyService {

    @Resource
    StrategyMapper strategyMapper;
    @Override
    public List<TStrategyConfig> findList(TStrategyConfig tStrategyConfig) {
        List<TStrategyConfig> tStrategyConfigs = strategyMapper.findList(tStrategyConfig);
        return tStrategyConfigs;
    }

    @Override
    public int insert(TStrategyConfig tStrategyConfig) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        tStrategyConfig.setStrategyId(Long.parseLong(StringUtils.generateRandomNumber(8)+""));
        tStrategyConfig.setInsertTime(new Date());
        tStrategyConfig.setInsertUser(loginUser.getUser().getUserId()+"");
        tStrategyConfig.setUpdateTime(new Date());
        tStrategyConfig.setUpdateUser(loginUser.getUser().getUserId()+"");
        tStrategyConfig.setIsDelete("0");
        return strategyMapper.insert(tStrategyConfig);
    }

    @Override
    public int update(TStrategyConfig tStrategyConfig) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        tStrategyConfig.setUpdateTime(new Date());
        tStrategyConfig.setUpdateUser(loginUser.getUser().getUserId()+"");
        return strategyMapper.update(tStrategyConfig);
    }

    @Override
    public TStrategyConfig findById(Long strategyId) {
        TStrategyConfig tStrategyConfig = strategyMapper.findById(strategyId);
        return tStrategyConfig;
    }
}
